//
//  QuDanSearchContentViewCell.m
//  QuDanOEM
//
//  Created by xiaohuang on 2021/11/7.
//

#import "QuDanSearchContentViewCell.h"
#import "QuDanSquareNetWork.h"
@implementation QuDanSearchContentViewCell
- (void)awakeFromNib {
    [super awakeFromNib];
    self.iconImage.layer.cornerRadius = 45/2;
    self.iconImage.layer.masksToBounds = YES;
    self.bgView.layer.cornerRadius = 6.0f;
    self.bgView.layer.masksToBounds = YES;
    self.attenttioBtn.layer.cornerRadius = 2.0f;
    self.attenttioBtn.layer.masksToBounds = YES;
}

- (void)setSearchModel:(QuDanSearchModel *)searchModel
{
    _searchModel = searchModel;
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:searchModel.imgUrl] placeholderImage:[UIImage imageNamed:@"qd_test"]];
    self.titleLab.text = [NSString stringWithFormat:@"%@",searchModel.nickName];
    self.idlabe.text = [NSString stringWithFormat:@"ID:%ld",(long)searchModel.id];
    self.fanlab.text = [NSString stringWithFormat:@"粉丝:%ld",(long)searchModel.follow];
    if (searchModel.follower == YES) {
        //已关注
        self.attenttioBtn.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(70, 35) direction:PageGradientChangeDirectionLevel startColor:PostColorP(0xD8D8D8,1) endColor:PostColorP(0xD8D8D8 ,1)];
        [self.attenttioBtn setTitle:@"已关注" forState:UIControlStateNormal];
    }else{
        //没有关注
        self.attenttioBtn.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(70, 35) direction:PageGradientChangeDirectionLevel startColor:PostColorP(0xFF5121,1) endColor:PostColorP(0xFFC021 ,1)];
        [self.attenttioBtn setTitle:@"+关注" forState:UIControlStateNormal];
    }
}
/// 关注btn
/// @param sender 关注btn
- (IBAction)actionAttentionBtn:(UIButton *)sender
{
    if (self.searchModel.follower == YES) {
        //取消关注
        NSMutableDictionary *param = [NSMutableDictionary dictionary];
        param[@"mId"] = PostManage.shareInstance.userModel.ids;
        param[@"obj"] = @(self.searchModel.id);
        param[@"type"] = @"0";
        NSLog(@"param%@",param);
        [[QuDanSquareNetWork shareInstance]requestSquareFllowOrCancel:param viewController:nil andBlock:^(id  _Nullable data, BOOL result) {
            NSLog(@"取消关注.data:%@",data);
            self.searchModel.follower = NO;
            self.attenttioBtn.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(70, 35) direction:PageGradientChangeDirectionLevel startColor:PostColorP(0xFF5121,1) endColor:PostColorP(0xFFC021 ,1)];
            [self.attenttioBtn setTitle:@"+关注" forState:UIControlStateNormal];
        }];
    }else{
        //关注
        NSMutableDictionary *param = [NSMutableDictionary dictionary];
        param[@"mId"] = PostManage.shareInstance.userModel.ids;
        param[@"obj"] = @(self.searchModel.id);
        param[@"type"] = @"1";
        [[QuDanSquareNetWork shareInstance]requestSquareFllowOrCancel:param viewController:nil andBlock:^(id  _Nullable data, BOOL result) {
            NSLog(@"关注用户.data:%@",data);
            self.searchModel.follower = YES;
            self.attenttioBtn.backgroundColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(70, 35) direction:PageGradientChangeDirectionLevel startColor:PostColorP(0xD8D8D8,1) endColor:PostColorP(0xD8D8D8 ,1)];
            [self.attenttioBtn setTitle:@"已关注" forState:UIControlStateNormal];
        }];
    }
}
@end
